define(
    [ "PDUtilDir/util",  "PDUtilDir/tool", "PDUtilDir/slidebar", "AppPathDir/utils"],
    function(Util, Tool, Slidebar, Common) {
        function updateSupportInit($scope, $compile) {
            return new updateSupport($scope, $compile);
        }
        function updateSupport($scope, $compile) {
            this.$scope = $scope;
            this.$compile = $compile;
        }
        updateSupport.fn = updateSupport.prototype;

        updateSupport.fn.init = function(data) {
            this.entity = data;
        };

        updateSupport.fn.digest = function() {
            this.$scope.$digest();
        };
        updateSupport.fn.run = function(data) {
            var _this = this;
            _this.init(data);
            this.slidebars = Slidebar({
                size : 'lg',
                url : getServer()
                + "/static/app/product/productInfos/views/updateTimetable.html",
                $scope : this.$scope,
                $compile : this.$compile,
                afterLoad : function($Panel) {
                    _this.initialization();
                }
            });
        };
        updateSupport.fn.initialization = function() {
            this.timetableInit();
        };

        updateSupport.fn.timetableInit = function() {
            $("#dateName").datetimepicker({
                // 设置使用语言：cn是自定义的中文版本，还可以扩展其他语言版本
                language : "cn",
                // 输出格式化
                format : 'yyyy-mm-dd',
                // 直接选择‘今天’
                todayBtn : true,
                // 设置最精确的时间选择视图
                minView : 'month',
                // 高亮当天日期
                todayHighlight : true,
                // 选择完毕后自动关闭
                autoclose : true
            });
        };

        updateSupport.fn.save = function() {
            var _this = this;
            $.ajax({
                url : getServer() + "/flea/hclv/product/updateTimeTableByProductId.htmls",
                data : {
                    'model' : JSON.stringify({
                        productId: _this.$scope.entity.product.id,
                        timeTable: _this.entity
                    })
                },
                success : function(data) {
                    if (data.status != 200) {
                        return;
                    }
                    _this.$scope.grid.refresh();
                    Util.alert('成功');
                    _this.slidebars.close();
                }
            });
        };
        return updateSupportInit;
    });